package com.yunying.rispro.service.impl;

import com.yunying.rispro.model.Doctor;
import com.yunying.rispro.service.IRedisService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import java.util.concurrent.TimeUnit;

@Service
public class RedisServiceImpl implements IRedisService {

    @Autowired
    private RedisTemplate<String,Object> redisTemplate;

    @Override
    public void setUserToRedis(String token, Doctor doctor) {
        redisTemplate.opsForValue().set(token,doctor,1800L, TimeUnit.SECONDS);
    }

    @Override
    public Doctor getUserByToken(String token) {
        return (Doctor) redisTemplate.opsForValue().get(token);
    }

    @Override
    public boolean deleteToken(String token) {
        return redisTemplate.delete(token);
    }
}
